##########################################################################################################
# REPLICATION CODE FOR                                                                                   #
# "Conspiracy beliefs and perceptions of electoral integrity: Cross-national evidence from 29 countries" #
# PUBLIC OPINION QUARTERLY																										                           #
#																																                                         #
# AUTHOR: Christian Schnaudt (corresponding author)                                                      #
# ADDRESS: School of Social Sciences, University of Mannheim, 68131 Mannheim, Germany                    # 
# E-MAIL: schnaudt@uni-mannheim.de 																								                       #
# ORCID: 0000-0002-2062-7770																									                           #   
#																																                                         #
# VERSION DATE: 2023-10-06							                                                                 #   
##########################################################################################################


# 1 SETUP (SET WD, LOAD PACKAGES AND DATA)

# SET WORKING DIRECTORY
# IMPORTANT: ADJUST THE PATH BELOW TO YOUR PERSONAL WORKING ENVIRONMENT
setwd("C:/Users/user/Desktop/REPLICATION FILES")

# LOAD REQUIRED PACKAGES
library(haven)
library(dplyr)
library(lme4)
library(sjPlot)
library(sjlabelled)
library(sjmisc)
library(ggplot2)
library(ggpubr)
library(tidyverse)
library(jtools)
library(ggstance)
library(effects)
library(dplyr)
library(interplot)
library(GGally)
library(gghighlight)
library(labelled)
library(Rmisc)
library(RColorBrewer)
library(lmerTest)
library(ggeffects)
library(readstata13)
library(glmmTMB)
library(psych)


# LOAD DATA
ess<-read_dta("data_analysis.dta")

##########################################################################################################

# 2 PREPARATION: DEFINE FACTOR VARIABLES FOR REGRESSION MODELS

# survey mode
ess$mode<-factor(ess$mode, levels = c(1,2,3,4), 
                 labels = c("F2F", "Video interview", "Self-admin: web", "Self-admin: paper"))
summary(ess$mode)

# electoral winner/loser
table(ess$winner2)
ess$winner2<-factor(ess$winner2, levels = c(0,1,2,3,4),  
                    labels = c("Loser", "Winner", "Non-voters", "Voters (w/o status)", "Ineligibles"))
summary(ess$winner2)

# single item conspiracy beliefs: scientists
table(ess$scidecpbr)
ess$scidecpbr_fac<-factor(ess$scidecpbr, levels = c(0,1,2,3,4))

# single item conspiracy beliefs: secret group
table(ess$secgrdecr)
ess$secgrdecr_fac<-factor(ess$secgrdecr, levels = c(0,1,2,3,4))

# ESS country variables
ess$cntry<-as.factor(ess$cntry)
ess$cntry2<-factor(ess$cntrynum, levels = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
                                            16,17,18,19,20,21,22,23,24,25,26,27,28,29),
                   labels = c("Austria", "Belgium", "Bulgaria", "Switzerland",
                              "Cyprus", "Czech Republic", "Germany", "Estonia",
                              "Spain","Finland", "United Kingdom", "Greece", "Croatia",
                              "Hungary", "Ireland", "Israel", "Iceland", "Italy",
                              "Lithuania", "Latvia", "North Macedonia", "Netherlands",
                              "Norway", "Poland", "Portugal","Serbia", "Sweden", 
                              "Slovenia", "Slovakia"))
summary(ess$cntry2)


##########################################################################################################

# 3 REGRESSION MODELS: MAIN ANALYSIS

# empty model
model1<-lmer(fairelcc~1+
               (1|cntry), ess, verbose=T, weights=anweight)
summary(model1)

#########################

# individual-level, conspiracy items only
model2<-lmer(fairelcc~1+ conspi_nm +
               (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model2)


model2a_fac<-lmer(fairelcc~1+ secgrdecr_fac +
                    (1+secgrdecr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model2a_fac)


model2b_fac<-lmer(fairelcc~1+ scidecpbr_fac +
                    (1+scidecpbr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model2b_fac)

#########################

# full individual-level models, incl. covariates
model3<-lmer(fairelcc~1 + conspi_nm + 
               distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
               lrscale_nm + pid +  winner2 + meduse_nm +
               age_nm + female + eduyrs_nm + mode +
               (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model3)

model3a_fac<-lmer(fairelcc~1 + secgrdecr_fac + 
                    distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                    lrscale_nm + pid+ winner2 + meduse_nm +
                    age_nm + female + eduyrs_nm + mode +
                    (1+secgrdecr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model3a_fac)

model3b_fac<-lmer(fairelcc~1 + scidecpbr_fac + 
                    distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                    lrscale_nm + pid+ winner2 +  meduse_nm +
                    age_nm + female + eduyrs_nm + mode +
                    (1+scidecpbr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model3b_fac)


#########################

# contextual-level integrity only (no ind. variables)
model4<-lmer(fairelcc~1 + ei_index_vdem +
               (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model4)


#########################

# individual-level integrity + contextual-level integrity 
model5<-lmer(fairelcc~1+ conspi_nm + ei_index_vdem +
               (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model5)

model5a_fac<-lmer(fairelcc~1+ secgrdecr_fac + ei_index_vdem +
                (1+secgrdecr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model5a_fac)

model5b_fac<-lmer(fairelcc~1+ scidecpbr_fac + ei_index_vdem +
                (1+scidecpbr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model5b_fac)


# full models with all individual-level and contextual-level covariates 
model6<-lmer(fairelcc~1 + conspi_nm +
               distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
               lrscale_nm + pid+ winner2 + meduse_nm +
               age_nm + female + eduyrs_nm + mode +
               gdppc_nm + v2elcomvot + ei_index_vdem +
               (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model6)

#with "cname" for labels
model6c<-lmer(fairelcc~1 + conspi_nm +
                distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                lrscale_nm + pid+ winner2 + meduse_nm +
                age_nm + female + eduyrs_nm + mode +
                gdppc_nm + v2elcomvot + ei_index_vdem +
                (1+conspi_nm|cname), ess, verbose=T, weights=anweight)
summary(model6c)

model6a_fac<-lmer(fairelcc~1 + secgrdecr_fac +
                    distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                    lrscale_nm + pid+  winner2 + meduse_nm +
                    age_nm + female + eduyrs_nm + mode +
                    gdppc_nm + v2elcomvot + ei_index_vdem +
                    (1+secgrdecr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model6a_fac)

model6b_fac<-lmer(fairelcc~1 + scidecpbr_fac +
                    distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                    lrscale_nm + pid+  winner2 + meduse_nm +
                    age_nm + female + eduyrs_nm + mode +
                    gdppc_nm + v2elcomvot + ei_index_vdem +
                    (1+scidecpbr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model6b_fac)


# simple interaction models without covariates 
model7<-lmer(fairelcc~1 + conspi_nm +
               ei_index_vdem +
               conspi_nm:ei_index_vdem +
               (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model7)

model7a_fac<-lmer(fairelcc~1 + secgrdecr_fac +
                ei_index_vdem +
                secgrdecr_fac:ei_index_vdem +
                (1 + secgrdecr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model7a_fac)

model7b_fac<-lmer(fairelcc~1 + scidecpbr_fac +
                ei_index_vdem +
                scidecpbr_fac:ei_index_vdem +
                (1 + scidecpbr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model7b_fac)

# full interaction models incl. covariates
model8<-lmer(fairelcc~1 + conspi_nm +
               distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
               lrscale_nm + pid+ winner2 + meduse_nm +
               age_nm + female + eduyrs_nm + mode +
               gdppc_nm + v2elcomvot + ei_index_vdem +
               conspi_nm:ei_index_vdem +
               (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model8)

model8a_fac<-lmer(fairelcc~1 + secgrdecr_fac +
                    distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                    lrscale_nm + pid + winner2 +  meduse_nm +
                    age_nm + female + eduyrs_nm + mode +
                    gdppc_nm + v2elcomvot + ei_index_vdem +
                    secgrdecr_fac:ei_index_vdem +
                    (1 + secgrdecr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model8a_fac)

model8b_fac<-lmer(fairelcc~1 + scidecpbr_fac +
                    distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                    lrscale_nm + pid + winner2 + meduse_nm +
                    age_nm + female + eduyrs_nm + mode +
                    gdppc_nm + v2elcomvot + ei_index_vdem +
                    scidecpbr_fac:ei_index_vdem +
                    (1 + scidecpbr_fac|cntry), ess, verbose=T, weights=anweight)
summary(model8b_fac)


# individual-level interaction between conspiracy beliefs and status as winner/loser
model9<-lmer(fairelcc~1 + conspi_nm + winner2 +
               distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
               lrscale_nm + pid +  meduse_nm +
               age_nm + female + eduyrs_nm + mode +
               gdppc_nm + v2elcomvot + ei_index_vdem +
               conspi_nm:winner2 +
               (1 + conspi_nm + winner2|cntry), ess, verbose=T, weights=anweight)
summary(model9)

####################################################################################################

# 4 REGRESSION MODELS: ADDITIONAL ANALYSES AND ROBUSTNESS CHECKS

# EXTENDED MODELS WITH SUBFACETS OF V-DEM CLEAN ELECTIONS INDEX & NELDA INDEX

# 4A MODELS WITH NELDA INDEX
model6r2<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + nelda_index_nm +
                 (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model6r2)

model7r2<-lmer(fairelcc~1 + conspi_nm +
                 nelda_index_nm +
                 conspi_nm:nelda_index_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model7r2)

model8r2<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + nelda_index_nm +
                 conspi_nm:nelda_index_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model8r2)


# 4B: MODELS WITH V-DEM v2elembaut_nm EMB autonomy
model6r3<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elembaut_nm +
                 (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model6r3)

model7r3<-lmer(fairelcc~1 + conspi_nm +
                 v2elembaut_nm +
                 conspi_nm:v2elembaut_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model7r3)

model8r3<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elembaut_nm +
                 conspi_nm:v2elembaut_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model8r3)


# 4C: MODELS WITH V-DEM v2elembcap_nm EMB capacity
model6r4<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elembcap_nm +
                 (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model6r4)

model7r4<-lmer(fairelcc~1 + conspi_nm +
                 v2elembcap_nm +
                 conspi_nm:v2elembcap_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model7r4)

model8r4<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elembcap_nm +
                 conspi_nm:v2elembcap_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model8r4)


# 4D: MODELS WITH V-DEM v2elrgstry_nm election voter registry
model6r5<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elrgstry_nm +
                 (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model6r5)

model7r5<-lmer(fairelcc~1 + conspi_nm +
                 v2elrgstry_nm +
                 conspi_nm:v2elrgstry_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model7r5)

model8r5<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elrgstry_nm +
                 conspi_nm:v2elrgstry_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model8r5)


# 4D: MODELS WITH V-DEM v2elvotbuy_nm election vote buying
model6r6<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elvotbuy_nm +
                 (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model6r6)

model7r6<-lmer(fairelcc~1 + conspi_nm +
                 v2elvotbuy_nm +
                 conspi_nm:v2elvotbuy_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model7r6)

model8r6<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elvotbuy_nm +
                 conspi_nm:v2elvotbuy_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model8r6)



# 4E: MODELS WITH V-DEM v2elirreg_nm election other voting irregularities
model6r7<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elirreg_nm +
                 (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model6r7)

model7r7<-lmer(fairelcc~1 + conspi_nm +
                 v2elirreg_nm +
                 conspi_nm:v2elirreg_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model7r7)


model8r7<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elirreg_nm +
                 conspi_nm:v2elirreg_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model8r7)


# 4F: MODELS WITH V-DEM v2elintim_nm election government intimidation
model6r8<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elintim_nm +
                 (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model6r8)

model7r8<-lmer(fairelcc~1 + conspi_nm +
                 v2elintim_nm +
                 conspi_nm:v2elintim_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model7r8)


model8r8<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elintim_nm +
                 conspi_nm:v2elintim_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model8r8)


# 4G: MODELS WITH V-DEM v2elpeace_nm non-state electoral violence
model6r9<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elpeace_nm +
                 (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model6r9)

model7r9<-lmer(fairelcc~1 + conspi_nm +
                 v2elpeace_nm +
                 conspi_nm:v2elpeace_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model7r9)

model8r9<-lmer(fairelcc~1 + conspi_nm +
                 distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                 lrscale_nm + pid+ winner2 + meduse_nm +
                 age_nm + female + eduyrs_nm + mode +
                 gdppc_nm + v2elcomvot + v2elpeace_nm +
                 conspi_nm:v2elpeace_nm +
                 (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model8r9)



# 4H: MODELS WITH V-DEM v2elfrfair_nm election free and fair
model6r10<-lmer(fairelcc~1 + conspi_nm +
                  distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                  lrscale_nm + pid+ winner2 + meduse_nm +
                  age_nm + female + eduyrs_nm + mode +
                  gdppc_nm + v2elcomvot + v2elfrfair_nm +
                  (1+conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model6r10)

model7r10<-lmer(fairelcc~1 + conspi_nm +
                  v2elfrfair_nm +
                  conspi_nm:v2elfrfair_nm +
                  (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model7r10)

model8r10<-lmer(fairelcc~1 + conspi_nm +
                  distrst_nm + stfeco_nm + polintr_nm + inteff_nm + 
                  lrscale_nm + pid+ winner2 + meduse_nm +
                  age_nm + female + eduyrs_nm + mode +
                  gdppc_nm + v2elcomvot + v2elfrfair_nm +
                  conspi_nm:v2elfrfair_nm +
                  (1 + conspi_nm|cntry), ess, verbose=T, weights=anweight)
summary(model8r10)


####################################################################################################
